# @Desc    : do what 
# @Author  : meihongliang  
# @Time    : 2025-03-22 21:25
import pandas as pd
import mplfinance as mpf


def kline_mpt():
    # 示例数据（日期、开盘价、最高价、最低价、收盘价）
    data = {
        'Date': ['2023-10-01', '2023-10-02', '2023-10-03', '2023-10-04', '2023-10-05'],
        'Open': [100, 105, 110, 108, 112],
        'High': [102, 108, 112, 111, 115],
        'Low': [98, 103, 108, 107, 110],
        'Close': [101, 107, 109, 110, 113]
    }

    # 转换为 DataFrame
    df = pd.DataFrame(data)
    df['Date'] = pd.to_datetime(df['Date'])
    df.set_index('Date', inplace=True)

    # 绘制蜡烛图
    mpf.plot(df, type='candle', style='charles', title='K-line', volume=False)

    # 计算 5 日移动平均线
    # df['MA5'] = df['Close'].rolling(window=5).mean()
    #
    # # 绘制移动平均线
    # mpf.plot(df, type='candle', style='charles', title='K 线图', volume=False, addplot=mpf.make_addplot(df['MA5']))


if __name__ == '__main__':
    kline_mpt()
